/*
** xfunc.c for xfunc in /home/vriely/Dropbox/work/Unix/Zappy_none/serv-src
**
** Made by
** Login   <@epitech.net>
**
** Started on  Wed May 16 21:09:13 2012
** Last update Thu Jul 19 18:23:49 2012 pierrick druart
*/

#include		<stdio.h>
#include		<unistd.h>
#include		<stdlib.h>

#include		"server.h"

void			xclose(int fd)
{
  if (close(fd) == -1)
    perror("close()");
}

void			xfclose(FILE *fd)
{
  if (fclose(fd) == -1)
    perror("fclose()");
}

FILE			*xfopen(char *path, char *mode)
{
  FILE			*fd;

  fd = fopen(path, mode);
  if (fd == NULL)
    perror("fopen()");
  return (fd);
}

void			*xcalloc(size_t nmemb, size_t size)
{
  char			*ptr;

  ptr = calloc(nmemb, size);
  if (ptr == NULL)
  {
    perror("xcalloc");
    exit(EXIT_FAILURE);
  }
  return (ptr);
}

void			*xmalloc(size_t size)
{
  void			*return_value;

  return_value = malloc(size);
  if (return_value == NULL)
    {
      perror("xmalloc");
      exit(EXIT_FAILURE);
    }
  return (return_value);
}
